package com.pocket.insight.base.mql;

import com.pocket.insight.entity.Type;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 描述：
 *
 * @author shuize
 * @create 2024/11/30
 */
public interface DF {


    class Signature implements Cloneable {
        private Type.TypeName       type;
        private List<DF.Argument>   args;
        private String              desc;
        private String              name;
        private List<String>        categories;
        private Map<String, String> presets;
        private Boolean             varArgs;
        private Boolean             isAggregate;
        private Boolean             isWindow;

        public Signature(String name, Type.TypeName type, List<DF.Argument> args) {
            this.name = name;
            this.type = type;
            this.args = args;
        }


        public boolean isVarArgs() {
            if (this.varArgs != null) {
                return this.varArgs.booleanValue();
            }
            MDF hdf = MDF.fromString(this.name);
            return (MDF.CONCAT == hdf || MDF.isOperator(this.name) || MDF.ARRAY == hdf || MDF.LEAST == hdf || MDF.GREATEST == hdf || MDF.JSON_BUILD_ARRAY == hdf || (
                    Objects.requireNonNull(hdf)).compareTo(MDF.MDF_WINDOW_REWRITE_BEGIN) > 0);
        }
    }


    @Data
    @NoArgsConstructor
    class Argument implements Cloneable {
        private Type.TypeName type;
        private String        placeholder;
        private String        desc;

        public Argument(Type.TypeName type, String placeholder) {
            this.type = type;
            this.placeholder = placeholder;
        }
    }

}
